package com.bolt.admin.config;

import com.bolt.admin.web.view.freemarker.AuthMenuModel;
import com.bolt.admin.web.view.freemarker.DataGridModel;
import com.bolt.admin.web.view.freemarker.UserInfoMethodModel;
import com.bolt.core.view.freemarker.BoltTags;
import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import javax.annotation.PostConstruct;

/**
 * Created by Administrator on 2019/4/23.
 */
@Component
public class PlatformFreeMarkerConfigurer {
    @Autowired
    private FreeMarkerConfigurer freeMarkerConfigurer;

    @Value("#{servletContext.contextPath}")
    private String contextPath;

    @PostConstruct
    public void setSharedVariable() throws TemplateModelException {
        freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags());
        freeMarkerConfigurer.getConfiguration().setSharedVariable("base", contextPath);
        freeMarkerConfigurer.getConfiguration().setSharedVariable("bolt", new BoltTags());
        freeMarkerConfigurer.getConfiguration().setSharedVariable("authMenu", new AuthMenuModel());
        freeMarkerConfigurer.getConfiguration().setSharedVariable("dataGrid", new DataGridModel());
        freeMarkerConfigurer.getConfiguration().setSharedVariable("userInfo", new UserInfoMethodModel());
//        ClassTemplateLoader viewLoader = new ClassTemplateLoader(getClass(), "/templates");
//        ClassTemplateLoader uiLoader = new ClassTemplateLoader(FreeMarkerFactory.class, "/templates");
//        MultiTemplateLoader templateLoader = new MultiTemplateLoader(new TemplateLoader[] {viewLoader});
//        freeMarkerConfigurer.getConfiguration().setTemplateLoader(templateLoader);


    }


}

 